package com.wlf.service.impl;

import com.wlf.dao.UserMapper;
import com.wlf.entity.User;
import com.wlf.entity.UserExample;
import com.wlf.service.IUserService;
import com.wlf.util.CommonFunctions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author 作者 危凌峰:
* @version 创建时间：2021年4月28日 上午9:39:49
*/
@Service
@Transactional
public class UserServiceImpl implements IUserService{

	@Autowired
	private UserMapper userMapper;


	@Override
	public User getUser(User user) {
		UserExample example =new UserExample();
		example.createCriteria().andUsernameEqualTo(user.getUsername())
				.andPasswordEqualTo(user.getPassword());
		List<User> userList = userMapper.selectByExample(example);
		if(CommonFunctions.isEmpty(userList))
			return null;
		return userList.get(0);
	}

	@Override
	public void insert(User user) {
		userMapper.insert(user);
	}
}
